﻿using Devonline.AspNetCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace Devonline.Identity;

/// <summary>
/// 基于 DataService 的数据及视图模型增删改查的基础控制器
/// </summary>
/// <typeparam name="TEntitySet">业务数据类型</typeparam>
/// <typeparam name="TViewModel">业务数据类型的视图模型类型</typeparam>
/// <typeparam name="TKey">主键类型</typeparam>
[Authorize]
[ApiController]
public abstract class DataModelServiceController<TEntitySet, TViewModel, TKey> :
    DataModelServiceController<IdentityDbContext, TEntitySet, TViewModel, TKey>
    where TEntitySet : class, IEntitySet<TKey>
    where TViewModel : class, IViewModel<TKey>
    where TKey : IConvertible
{
    public DataModelServiceController(
        ILogger<DataModelServiceController<TEntitySet, TViewModel, TKey>> logger,
        IDataService<TEntitySet, TKey> dataService
        ) : base(logger, dataService) { }
}

/// <summary>
/// 基于字符串作为主键的 DataService 的数据增删改查的基础控制器
/// </summary>
/// <typeparam name="TEntitySet">业务数据类型</typeparam>
/// <typeparam name="TViewModel">业务数据类型的视图模型类型</typeparam>
[Authorize]
[ApiController]
public abstract class DataModelServiceController<TEntitySet, TViewModel> :
    DataModelServiceController<TEntitySet, TViewModel, string>
    where TEntitySet : class, IEntitySet
    where TViewModel : class, IViewModel
{
    public DataModelServiceController(
        ILogger<DataModelServiceController<TEntitySet, TViewModel>> logger,
        IDataService<TEntitySet> dataService
        ) : base(logger, dataService) { }
}